# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libslirp
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=4.3.0
pkgrel=2
pkgdesc="General purpose TCP-IP emulator (mingw-w64)"
arch=('any')
url="https://gitlab.freedesktop.org/slirp/libslirp"
license=('BSD' 'MIT')
depends=("${MINGW_PACKAGE_PREFIX}-glib2")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-ninja")
#"https://gitlab.freedesktop.org/slirp/${_realname}/-/archive/v${pkgver}/${_realname}-v${pkgver}.tar.bz2"
source=("https://elmarco.fedorapeople.org/${_realname}-${pkgver}.tar.xz")
sha256sums=('4866cce89b0e129abebe3e34c7dd3d33145537e3bc77efeeb46e7d9589c13625')

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir -p ${srcdir}/build-${MINGW_CHOST} && cd ${srcdir}/build-${MINGW_CHOST}

  ${MINGW_PREFIX}/bin/meson \
    --buildtype=plain \
    -Ddefault_library=both \
    ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/ninja
}

package() {
  cd build-${MINGW_CHOST}
  DESTDIR="${pkgdir}${MINGW_PREFIX}" ${MINGW_PREFIX}/bin/ninja install
  install -Dm644 ${srcdir}/${_realname}-${pkgver}/COPYRIGHT ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYRIGHT

  local _PRE_WIN="$(cygpath -m ${MINGW_PREFIX})"
  for pcfile in  "${pkgdir}${MINGW_PREFIX}"/lib/pkgconfig/*.pc; do
    sed -s "s|${_PRE_WIN}|${MINGW_PREFIX}|g" -i "${pcfile}"
  done
}
